package com.it.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class    WebMvcConfiguration implements WebMvcConfigurer {

    @Override  // 资源映射
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        //上传的图片在D盘下的OTA目录下，访问路径如：http://localhost:8081/OTA/d3cf0281-bb7f-40e0-ab77-406db95ccf2c.jpg
        //其中OTA表示访问的前缀。"file:D:/OTA/"是文件真实的存储路径
        String property = System.getProperty("user.dir");

        registry.addResourceHandler("/upload/**").addResourceLocations("file:" + property + "\\api\\src\\main\\resources\\upload\\");
//        registry.addResourceHandler("/upload/**").addResourceLocations("file:img/");
        registry.addResourceHandler("/upload02/**").addResourceLocations("file:" + property + "\\api\\src\\main\\resources\\upload02\\");
//        registry.addResourceHandler("/")
    }

    public static void main(String[] args) {
        String property = System.getProperty("user.dir");
        System.out.println("property = " + property);
        String s = "file:" + property + "\\api\\src\\main\\resources\\upload\\";
//        System.out.println("s = " + s);
    }
}
